package com.gm.wholesale.module.custom.model;

import com.gm.commonlib.base.baseBean.BaseResp;
import com.gm.commonlib.base.baseBean.DataResp;
import com.gm.commonlib.base.baseView.IBaseView;
import com.gm.commonlib.base.baseui.baseFragment.BaseFragment;
import com.gm.commonlib.network.BaseHttpObserver;
import com.gm.commonlib.network.HttpClient;
import com.gm.commonlib.network.HttpServicesHolder;
import com.gm.wholesale.module.custom.api.ICustomApi;
import com.gm.wholesale.module.custom.bean.DefaultCustomBean;

import java.util.HashMap;

import io.reactivex.Observable;

public class CustomModel {
    //获取默认散客用户信息
    public static void getDefaultCustom(BaseFragment fragment, BaseHttpObserver<DataResp<DefaultCustomBean>> observer) {
        HttpClient.sendRequest(fragment, new HttpServicesHolder<ICustomApi, DataResp<DefaultCustomBean>>() {
            @Override
            public Observable<DataResp<DefaultCustomBean>> getHttpObservable(ICustomApi instance) {
                return instance.getDefaultCustomers();
            }
        }, observer);
    }



    //删除客户
    public static void deleteCustorm(IBaseView iBaseView, long id, int version,BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<ICustomApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(ICustomApi instance) {
                return instance.deleteCustomer(id,version);
            }
        }, observer);
    }


    //新增客户
    public static void addCustorm(IBaseView iBaseView, HashMap<String,Object> data, BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<ICustomApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(ICustomApi instance) {
                return instance.addCustorm(data);
            }
        }, observer);
    }


    //修改
    public static void updateCustorm(IBaseView iBaseView,long id, HashMap<String,Object> data, BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<ICustomApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(ICustomApi instance) {
                return instance.updateCustorm(id,data);
            }
        }, observer);
    }



    public static void getInviteOrder(IBaseView iBaseView,long id,  BaseHttpObserver<DataResp<String>> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<ICustomApi, DataResp<String>>() {
            @Override
            public Observable<DataResp<String>> getHttpObservable(ICustomApi instance) {
                return instance.getInviteOrder(id);
            }
        }, observer);
    }
}
